;;;;;;;;;;;;;;;;;;;;  additional plugins  ;;;;;;;;;;;;;;;;;;;;
(require 'pysmell)
(require 'python-mode)
(require 'pycomplete)
(require 'anything)
(require 'ipython)
(require 'comint)
(require 'anything-ipython)
;;;;;;;;;;;;;;;;;;;;  hook  ;;;;;;;;;;;;;;;;;;;;
(add-hook 'python-mode-hook '(lambda ()
                               (progn
                                 (define-key py-mode-map (kbd "C-<tab>") 'company-ropemacs)
                                 (define-key py-mode-map "\C-m" 'newline-and-indent)
                                 (pysmell-mode 1)
                                 ;; (flyspell-prog-mode)
                                 (my-c-mode-auto-pair)
                                 (outline-minor-mode)
                                 ;; (py-complete-init)
                                 (company-mode)
                                 )))

(add-hook 'ipython-shell-hook '(lambda () (define-key py-mode-map (kbd "<tab>") 'anything-ipython-complete)))

;;;;;;;;;;;;;;;;;;;;  ipython shell  ;;;;;;;;;;;;;;;;;;;;
(define-key comint-mode-map [(meta p)] 
  'comint-previous-matching-input-from-input)
(define-key comint-mode-map [(meta n)] 
  'comint-next-matching-input-from-input)
(define-key comint-mode-map [up]
  'comint-next-input)
(define-key comint-mode-map [down]
  'comint-previous-input)
(setq ipython-command emax-python-command)
(setq py-python-command emax-python-command)
(setq py-python-command-args '("-pylab" "-colors" "LightBG"))
(setq ansi-color-for-comint-mode t)
(setq python-python-command "python")

;;;;;;;;;;;;;;;;;;;;  python basic setting  ;;;;;;;;;;;;;;;;;;;;
(autoload 'jython-mode "python-mode" "Python editing mode." t)
(autoload 'python-mode "python-mode" "Python Mode." t)
(autoload 'py-shell "python-mode" "Start an interactive Python interpreter in another window." t)
(autoload 'doctest-mode "doctest-mode" "Editing mode for Python Doctest examples." t)
(autoload 'py-complete-init "py-complete")
(autoload 'py-complete "pycomplete" "Complete a symbol at point using Pymacs." t)
(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
(add-to-list 'auto-mode-alist '("\\.doctest$" . doctest-mode))

;;;;;;;;;;;;;;;;;;;;  pylint  ;;;;;;;;;;;;;;;;;;;;
(defun flymake-pylint-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list "epylint" (list local-file))))
(load-library "pylint")
(add-to-list 'flymake-allowed-file-name-masks
             '("\\.py\\'" flymake-pylint-init))

;;;;;;;;;;;;;;;;;;;;  pymacs  ;;;;;;;;;;;;;;;;;;;;
(require 'pymacs)
(setenv "PYMACS_PYTHON" "python2.7")
(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
(autoload 'pymacs-load "pymacs" nil t)
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-exec "pymacs" nil t)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-confirm-saving 'nil)
(setq ropemacs-enable-autoimport 't)
(setq ropemacs-autoimport-modules '("os" "sys" "time" "shutil"))

;;;;;;;;;;;;;;;;;;;;  junk  ;;;;;;;;;;;;;;;;;;;;
;; (defun start-python()
;;   (interactive)
;;(when (equal noninteractive nil)

;; (defun flymake-pylint-init ()
;;     (let* ((temp-file (flymake-init-create-temp-buffer-copy
;;                        'flymake-create-temp-inplace))
;;            (local-file (file-relative-name
;;                         temp-file
;;                         (file-name-directory buffer-file-name))))
;;       (list "epylint" (list local-file)))

;; (add-to-list 'flymake-allowed-file-name-masks
;;                '("\\.py\\'" flymake-pylint-init)))
;;(setq py-python-command-args '( "-colors" "Linux"))
;;(setq py-python-command-args '("-colors" "Linux" "--autoindent"))
;; (when (load "flymake" t)
;;)
;;(add-to-list 'interpreter-mode-alist '("python" . python-mode))
;;(add-to-list 'interpreter-mode-alist '("jython" . jython-mode))
;;(require 'auto-complete)
